home *** CD-ROM | disk | FTP | other *** search
- ;----------------------------------------------------------------------------
- ; Copyright(C) 1996, The AEGiS Corporation
- ;----------------------------------------------------------------------------
- ;
- ; PROCEDURE Iemsi()
- ;
- ; Tests if user has IEMSI enabled (with Terminate for example)
- ; If IEMSI is available, information will be gathered and stored in
- ; Client... variables
- ;
- ; Note: IEMSI.MSG & IEMSI.CFG must be distributed along with your application
- ;
- ;----------------------------------------------------------------------------
- #lib
- #nouser
-
- Declare Function IEMSI_TickNow() Long
- Declare Function IEMSI_CodeHiAscii(bigstr str) BigStr
- Declare Function IEMSI_DecodeHiAscii(bigstr str) BigStr
- Declare Function IEMSI_DosToUnix(Date curdat, Time curtim) UNSIGNED
- Declare Procedure IEMSI_UnixToDos(unsigned dat, Var Date newDate, Var Time NewTime)
- Declare Procedure IEMSI_WriteLog()
- Declare Procedure IEMSI_MakeISIPacket()
- Declare Procedure IEMSI_FlushModem()
- Declare Procedure Iemsi()
- ;----------------------------------------------------------------------------
- Boolean IEMSI_OK
- String IEMSI_ClientName
- String IEMSI_ClientPassword
- String IEMSI_ClientAlias
- String IEMSI_ClientLocation
- String IEMSI_ClientDataPhone
- String IEMSI_ClientVoicePhone
- String IEMSI_ClientBirthdate
- String IEMSI_ClientSoftware
- String IEMSI_LogFile
- String IEMSI_BoardName
- String IEMSI_SysopName
- String IEMSI_BoardLocation
- String IEMSI_CR
- BigStr EMSI_IRQ
- BigStr EMSI_ACK
- BigStr EMSI_NAK
- BigStr EMSI_ICI
- BigStr EMSI_ISI
- Long IEMSI_Crc
- Long IEMSI_XorRot
- Boolean IEMSI_CrkTerminate
-
- Procedure Iemsi()
-
- ;----------------------------------------------------------------------------
- String IemsiCopyright
- Integer Timer1
- Integer Timer2
- Integer Tries
- ;----------------------------------------------------------------------------
- unsigned t
- integer RcvTries
- Date newdat
- Time newtim
- String k
- BigStr RcvString
- BigStr TempString
- Integer Count
- Integer A
- unsigned unixdate
- long crc2
- ;----------------------------------------------------------------------------
- String Msg(12)
- ;----------------------------------------------------------------------------
-
- IemsiCopyright = "φ AEGiS CoRP iEMSI iNTERFACE v1.2 φ By Lone Runner / AGS'96 φ"
- IEMSI_CR = Chr(13)
- EMSI_IRQ = "**EMSI_IRQ8E08"+IEMSI_CR
- EMSI_ACK = "**EMSI_ACKA490"+IEMSI_CR
- EMSI_NAK = "**EMSI_NAKEEC3"+IEMSI_CR
- EMSI_ICI = "**EMSI_ICI"
-
- If (onlocal()) Goto EndIemsi
-
- :tryiemsi
- IEMSI_LogFile = PPEPATH()+"IEMSI."+STRING(PCBNODE())
- If (Exist(IEMSI_LogFile)) Delete IEMSI_LogFile
-
- Fopen 1, PPEPath() + "IEMSI.MSG", O_RD, S_DN
- For a = 1 to 12
- FGet 1, Msg(a)
- next
- FClose 1
-
- IEMSI_BoardName = ReadLine(PPEPath()+"IEMSI.CFG",1)
- IEMSI_BoardLocation = ReadLine(PPEPath()+"IEMSI.CFG",2)
- IEMSI_SysopName = ReadLine(PPEPath()+"IEMSI.CFG",3)
- FClose -1
-
- SprintLn Msg(12)
- while (outbytes() != 0) do
- endwhile
-
- IEMSI_XorRot = S2i("FFFFFFFF",16) ; Init var XOR
-
- SPrintLn Msg(1) ; Advance session info
- Print ""
- Print IEMSI_CR
- MPrint EMSI_IRQ ; Send IEMSI request
- MPrint " "+IEMSI_CR ; Clear it in case no Iemsi is supported
-
- Tries = 0 ; Try #0!
-
- RcvString = "" ; Reset Buffer
-
- ; Wait for Iemsi answer
- IEMSI_MakeISIPacket() ; Create EMSI_ISI packet (we use the delay
- ; to lose as less time as possible)
- ;while (IEMSI_TickNow() < t + 36) do ; If the packet creation took less that 2s
- ;endwhile ; we complete the waiting
- ;
- ; ---> This seems to be unnecessary
-
- :GetICI
- Inc Tries ; New try
- If (Tries > 3) Goto EMSIFailed ; If more that 3 tries IEMSI failure
-
- t = IEMSI_TickNow() ; # of 1/18.2 since midnight
-
- While (1) Do
- k = MInkey() ; Read modem buffer
- RcvString = RcvString + k ; Add to the answer string
- If (k = IEMSI_CR) Break ; If CR received, we have all !
- if ((t+36 < IEMSI_TickNow()) && inbytes() = 0 ) break ; Goto nak1 ; No ? So we continue
- ; with a timeout of 1s & a condition : no more
- ; chars in the modem buffer
- EndWhile
-
- If (RcvString = "") Goto noIemsi
-
- If (len(RcvString) < 49) Then ; If the length is < 49 we take the following
- Goto GetICI ; part of it (49 = len of an empty packet)
- endif
-
- ; Handle received Packet
- :handleICI
-
- SprintLn Msg(3) ; Advance session info
-
- A = s2i(mid(RcvString,11,4),16) ; Get the Crc
- ;
- TempString = mid(RcvString,3,a+12) ;
- IEMSI_Crc = s2i(mid(RcvString,15+a,8),16) ;
- crc2 = CRC32(CRC_STR,TempString) ; Calculate real Crc from received pckt
- crc2 = XOR(crc2,IEMSI_XorRot) ;
- if (IEMSI_Crc != crc2) goto nak1 ; Compare them
-
- TempString = RcvString ; Temporary string
-
- TempString = IEMSI_DecodeHiAscii(TempString) ; Decode Hiascii ("\00" = Chr(0))
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientName = Left(TempString,A-1) ; User's Name !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientAlias = Left(TempString,A-1) ; User's Alias !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientLocation = Left(TempString,A-1) ; User's Location !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientDataPhone = Left(TempString,A-1) ; User's Dataphone !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientVoicePhone = Left(TempString,A-1) ; User's Voicephone !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientPassword = Left(TempString,A-1) ; User's Password !
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientBirthdate = Left(TempString,A-1) ; User's Date of Birth !
- if (IEMSI_ClientBirthdate != "") Then
- unixdate=S2i(IEMSI_ClientBirthdate,16) ; Convert UnixDate -> DosDate
- IEMSI_UnixToDos(unixdate,newdat,newtim)
- IEMSI_ClientBirthdate = String(newdat) ; End Convertion
- endif
-
- ; Didn't use a loop here so you can do exactly what you want with
- ; the received packet. \/
-
- A = Instr(TempString,"{") ; Jump one field
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"{") ; Jump one field
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"{") ; Jump one field
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"{") ; Jump one field
- TempString = Mid(TempString,A+1,Len(TempString)-A)
-
- A = Instr(TempString,"{")
- TempString = Mid(TempString,A+1,Len(TempString)-A)
- A = Instr(TempString,"}")
- IEMSI_ClientSoftware = Left(TempString,A-1) ; User's Software !
-
- if (instr(Chr(0)+" .",Right(IEMSI_ClientName,1))) then ; Does the name ends
- IEMSI_ClientName = Left(IEMSI_ClientName, Len(IEMSI_ClientName)-1) ; with a "." ?
- IEMSI_CrkTerminate = True ; Yes, so it's a
- endif ; cracked terminate :)
-
- If (Trim(IEMSI_ClientName, " ") = "") Then ; If the User's Name = "" so :
- Goto emsiFailed ; IEMSI failed
- else
- ; Else, display received
- ; informations on the local
- ; screen only!
- SPrintLn "******************************************************************************"
- If (IEMSI_ClientName != "") SPrintLn "Name : " + mid(IEMSI_ClientName,1,62)
- If (IEMSI_ClientPassword != "") SPrintLn "Password : " + mid(IEMSI_ClientPassword,1,62)
- If (IEMSI_ClientAlias != "") SPrintLn "Alias : " + mid(IEMSI_ClientAlias,1,62)
- If (IEMSI_ClientLocation != "") SPrintLn "Location : " + mid(IEMSI_ClientLocation,1,62)
- If (IEMSI_ClientDataPhone != "") SPrintLn "Data Phone : " + mid(IEMSI_ClientDataphone,1,62)
- If (IEMSI_ClientVoicePhone != "") SPrintLn "Voice Phone: " + mid(IEMSI_ClientVoicePhone,1,62)
- If (IEMSI_ClientBirthdate != "") SPrintLn "Birthdate : " + mid(IEMSI_ClientBirthdate,1,62)
- If (IEMSI_ClientSoftware != "") SPrintLn "Software : " + mid(IEMSI_ClientSoftware,1,62)
- If (IEMSI_CrkTerminate) SprintLn "Using Cracked Version of Terminate !"
- SPrintLn "******************************************************************************"
- Goto replyISI ; and go to answer!
- endif
-
-
- :nak1
- ; Crc were different !
- SprintLn Msg(5) ; Advance session info
- MPrint EMSI_NAK ; Send a NAK !
- Goto GetICI ; Go back to receive the packet
-
-
- :replyISI
- ; Client packet received, sending
- ; the server packet
- SprintLn Msg(6) ; Advance session info
-
- Tries = 0 ; Try #0
-
- ; Begin sending
- :SendISI
- SprintLn Msg(7) ; Advance session info
-
- MPrint EMSI_ISI ; Send EMSI_ISI (server package)
-
- ;Delay 25 ; ---> This was unnecessary...
-
- Inc Tries ; Inc tries
- If (Tries > 3) Goto EMSIFailed ; If tries > 3 so IEMSI failed!
-
- RcvString = "" ; Reset reception buffer
- t = IEMSI_TickNow() ; # of 1/18.2 since midnight
- rcvTries=1 ; Reception try #1
-
- :waitACK
- ; Waiting for ACK (EMSI ACKNOLEDGE)
- While (1) Do
- k = MInkey() ; Take an incoming modem char
- RcvString = RcvString + k ; Add it to the buffer
- If (k = IEMSI_CR) Break ; If CR, so we have all
- If ((t+36 < IEMSI_TickNow()) && inbytes() = 0) break
- ; If no CR, we wait
- ; with a timeout of
- ; 4s & condition:
- ; modem buffer empty
- EndWhile
-
- if (len(RcvString) < 15) then ; If len(buffer) < 15 (len of NAK & ACK)
- Inc rcvTries ; so inc RcvTries
- if (rcvTries < 4) then ; If no 3 tries to receive,
- goto waitACK ; so we go back to wait for the ACK
- else
- goto SendISI ; Else, resend the ISI packet
- endif
- endif
-
- If (Instr(RcvString,EMSI_NAK) != 0) Then ; Did we get a NAK ?
- SprintLn Msg(8) ; Yes! so advance session info
- IEMSI_MakeISIPacket()
- Goto SendISI ; and resend ISI packet
- endif
-
- if (Instr(RcvString,EMSI_ACK) != 0) Then ; Did we get an ACK ?
- :finiemsi
- SprintLn Msg(9) ; Yes! So advance session info
- SprintLn Msg(10) ; Advance session info (again, sorry ;)
-
- delay 4 ; delay 4/18.2s (the users has an IEMSI)
- ; window showing the server informations)
- ; ---> This is optionnal of course.
- IEMSI_OK = True
-
- IEMSI_WriteLog() ; Write the log.
- IEMSI_FlushModem() ; Flush input buffer, just in case...
- Goto Endiemsi ; Go back to normal login
- else ; Did not get the ACK ?
- Goto SendISI ; so resend ISI!
- EndIf
-
- :EMSIFailed
- ; IEMSI Failed
- ; Writing log
- ; WARNING: We do not write
- ; in the CALLERx. system log,
- ; it's not possible if we are in
- ; some special types of login PPE...
-
- FOPEN 1,IEMSI_LogFile,O_WR,S_DN
- fputln 1, "**************************************************************"
- fputln 1, "IEMSI HANDSHAKE FAILURE"
- fputln 1, "**************************************************************"
- fclose 1
- SprintLn Msg(11) ; Advance session info
- delay 5
- IEMSI_FlushModem() ; Flush the modem
- Goto EndIemsi ; Return to normal login
-
- :NoIemsi
- ; No IEMSI Capabilities
- ; Write the log
- FOPEN 1,IEMSI_LogFile,O_WR,S_DN
- fputln 1, "**************************************************************"
- fputln 1, "NO IEMSI CAPABILITIES"
- fputln 1, "**************************************************************"
- fclose 1
- SprintLn Msg(4) ; Advance session info
- delay 5
-
- :EndIemsi
-
- EndProc ; End of code!
-
- ;----------------------------------------------------------------------------
- ; This function returns the # of CPU ticks since midnight
- ;
- Function IEMSI_TickNow() LONG
- IEMSI_TickNow = PeekDW(MKADDR(0040h,006Ch))
- EndFunc
-
- ;----------------------------------------------------------------------------
- ; This function codes Hiascii's (Chr(0) -> "\00")
- ;
- Function IEMSI_CodeHiAscii(Bigstr str) BigStr
-
- String Temp
- word c
-
- Temp = ""
- for c = 1 to len(str)
- if (asc(mid(str,c,1)) <= 127 || mid(str,c,1) = "\") then
- Temp = Temp + mid(str,c,1)
- else
- Temp = Temp + "\"+i2s(asc(mid(str,c,1)),16)
- endif
- Next
- IEMSI_CodeHiAscii = Temp
- Endfunc
-
- ;----------------------------------------------------------------------------
- ; This function decodes Hiascii's ("\00"->Chr(0))
- ;
- Function IEMSI_DecodeHiAscii(Bigstr str) BigStr
-
- String Temp
- word c
-
- Temp = ""
- for c = 1 to len(str)
- if (mid(str,c,1) != "\") then
- Temp = Temp + mid(str,c,1)
- else
- Temp = Temp + chr(S2i(mid(str,c+1,2),16))
- c = c + 2
- endif
- Next
- IEMSI_DecodeHiAscii = Temp
- Endfunc
-
- ;----------------------------------------------------------------------------
- ; Write the log in a temporary file because it's not possible to write
- ; in the log at this location of PCB...
- ;
- Procedure IEMSI_WriteLog()
- Fcreate 1,IEMSI_LogFile,O_WR,S_DN
- fputln 1, "**************************************************************"
- If (IEMSI_ClientName != "") fputln 1, "Name : " + IEMSI_ClientName
- If (IEMSI_ClientPassword != "") fputln 1, "Password : " + IEMSI_ClientPassword
- If (IEMSI_ClientAlias != "") fputln 1, "Alias : " + IEMSI_ClientAlias
- If (IEMSI_ClientLocation != "") fputln 1, "Location : " + IEMSI_ClientLocation
- If (IEMSI_ClientDataPhone != "") fputln 1, "Data Phone : " + IEMSI_ClientDataphone
- If (IEMSI_ClientVoicePhone != "") fputln 1, "Voice Phone: " + IEMSI_ClientVoicePhone
- If (IEMSI_ClientBirthdate != "") fputln 1, "Birthdate : " + IEMSI_ClientBirthdate
- If (IEMSI_ClientSoftware != "") fputln 1, "Software : " + IEMSI_ClientSoftware
- If (IEMSI_CrkTerminate) fputln 1, "Using Cracked Version of Terminate !"
- fputln 1, "**************************************************************"
- fclose 1
- EndProc
-
- ;--------------------------------------------------------------------------
- ; DOSdate&time -> UNIXdate&time
- ;
- Function IEMSI_DosToUnix(Date curdat, Time curtim) UNSIGNED
- int annee
- int jour
- int mois
- unsigned dat
-
- Jour = Day(curdat)
- Mois = Month(curdat)
- Annee = Year(curdat)-1968
-
- if (annee % 4 = 0) then
- select case Mois
- case 2
- jour = jour + 31
- case 3
- jour = jour + 60
- case 4
- jour = jour + 91
- case 5
- jour = jour + 121
- case 6
- jour = jour + 152
- case 7
- jour = jour + 182
- case 8
- jour = jour + 213
- case 9
- jour = jour + 244
- case 10
- jour = jour + 274
- case 11
- jour = jour + 305
- case 12
- jour = jour + 335
- end select
- else
- select case Mois
- case 2
- jour = jour + 31
- case 3
- jour = jour + 59
- case 4
- jour = jour + 90
- case 5
- jour = jour + 120
- case 6
- jour = jour + 151
- case 7
- jour = jour + 181
- case 8
- jour = jour + 212
- case 9
- jour = jour + 243
- case 10
- jour = jour + 273
- case 11
- jour = jour + 304
- case 12
- jour = jour + 334
- end select
- end if
-
- dat = jour * 86400 + (annee - 2) * 365 * 86400 + (annee/4)*86400 + curtim
- IEMSI_DosToUnix = dat
- EndFunc
- ;----------------------------------------------------------------------------
- ; UNIX Date&time -> DOSdate&time
- ;
- Procedure IEMSI_UnixToDos(unsigned dat, Var Date newDate, Var Time NewTime)
- int annee
- int jour
- int heure
- int minute
- int mois
- unsigned seconde
-
- seconde = dat % 86400
- dat = dat / 86400
-
- annee = (dat / 365)+2
-
- jour = dat % 365 - annee/4
- inc jour
-
- NewDate = Jour + (Annee+68) * 365 + 17
- NewTime = Seconde
- EndProc
-
- ;----------------------------------------------------------------------------
- ; Making of the EMSI_ISI packet (SERVER PACKAGE)
- ;
- Procedure IEMSI_MakeISIPacket()
-
- BigStr TempString
- String Temp
-
- EMSI_ISI = "EMSI_ISI"
- TempString = "{PCBoard v"+ left(string(Ver()),2)+"."+mid(string(Ver()),3,1)
- if (mid(string(Ver()),4,1) != "0") TempString = Tempstring + mid(string(Ver()),4,1)
- TempString = TempString + "/"+string(MaxNode()) + "}{" + IEMSI_BoardName + "}{" + IEMSI_BoardLocation + "}{" + IEMSI_SysopName + "}{"+ I2s(IEMSI_DosToUnix(Date(), Time()),16) + "}{IEMSI Engine 1.2 (C)AEGiS}{\01}{}"
- TempString = IEMSI_CodeHiAscii(TempString)
- Temp = I2S(Len(TempString)+TempString,16)
- While (len(Temp) < 4) do
- Temp = "0"+Temp
- EndWhile
- EMSI_ISI = EMSI_ISI + Temp + TempString
- IEMSI_Crc=CRC32(CRC_STR,EMSI_ISI)
- IEMSI_Crc=XOR(IEMSI_Crc,IEMSI_XorRot)
- EMSI_ISI = "**" + EMSI_ISI + I2S(IEMSI_Crc,16)+IEMSI_CR
- EndProc
-
- ;----------------------------------------------------------------------------
- ; Flush the incoming buffer
- ;
- Procedure IEMSI_FlushModem()
- String k
-
- While (inbytes() > 0) do
- k = minkey()
- Endwhile
- Endproc
-
-